<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>字典包配置 | vue-element-dict</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/vue-element-dict/favicon.ico">
    <script defer="defer" async="async" src="https://cpro.baidustatic.com/cpro/ui/cm.js"></script>
    <meta name="description" content="vue-element-dict字典包官方使用文档">
    
    <link rel="preload" href="/vue-element-dict/assets/css/0.styles.2f302933.css" as="style"><link rel="preload" href="/vue-element-dict/assets/js/app.796ae7e4.js" as="script"><link rel="preload" href="/vue-element-dict/assets/js/4.df041e95.js" as="script"><link rel="preload" href="/vue-element-dict/assets/js/35.0a8dc5d9.js" as="script"><link rel="prefetch" href="/vue-element-dict/assets/js/1.9df3603b.js"><link rel="prefetch" href="/vue-element-dict/assets/js/10.55ebc9f1.js"><link rel="prefetch" href="/vue-element-dict/assets/js/11.ae1602ab.js"><link rel="prefetch" href="/vue-element-dict/assets/js/12.7a6d05ba.js"><link rel="prefetch" href="/vue-element-dict/assets/js/13.1d9a30ea.js"><link rel="prefetch" href="/vue-element-dict/assets/js/14.83cfdb89.js"><link rel="prefetch" href="/vue-element-dict/assets/js/15.c09cab0b.js"><link rel="prefetch" href="/vue-element-dict/assets/js/16.19c4ed7e.js"><link rel="prefetch" href="/vue-element-dict/assets/js/17.5c7fb955.js"><link rel="prefetch" href="/vue-element-dict/assets/js/18.b211f0fa.js"><link rel="prefetch" href="/vue-element-dict/assets/js/19.aa88b046.js"><link rel="prefetch" href="/vue-element-dict/assets/js/2.eb833b2e.js"><link rel="prefetch" href="/vue-element-dict/assets/js/20.740e71a2.js"><link rel="prefetch" href="/vue-element-dict/assets/js/21.814870f8.js"><link rel="prefetch" href="/vue-element-dict/assets/js/22.46503405.js"><link rel="prefetch" href="/vue-element-dict/assets/js/23.87118240.js"><link rel="prefetch" href="/vue-element-dict/assets/js/24.ac6635e4.js"><link rel="prefetch" href="/vue-element-dict/assets/js/25.f678ea41.js"><link rel="prefetch" href="/vue-element-dict/assets/js/26.d8cc5201.js"><link rel="prefetch" href="/vue-element-dict/assets/js/27.7078c96d.js"><link rel="prefetch" href="/vue-element-dict/assets/js/28.57b6222a.js"><link rel="prefetch" href="/vue-element-dict/assets/js/29.010701c9.js"><link rel="prefetch" href="/vue-element-dict/assets/js/30.c6e653d6.js"><link rel="prefetch" href="/vue-element-dict/assets/js/31.d1d5da99.js"><link rel="prefetch" href="/vue-element-dict/assets/js/32.6f3739df.js"><link rel="prefetch" href="/vue-element-dict/assets/js/33.d87a4b44.js"><link rel="prefetch" href="/vue-element-dict/assets/js/34.3eca72ee.js"><link rel="prefetch" href="/vue-element-dict/assets/js/36.121eaca2.js"><link rel="prefetch" href="/vue-element-dict/assets/js/37.dc841a6a.js"><link rel="prefetch" href="/vue-element-dict/assets/js/38.70886628.js"><link rel="prefetch" href="/vue-element-dict/assets/js/5.a10e50db.js"><link rel="prefetch" href="/vue-element-dict/assets/js/6.10b21df8.js"><link rel="prefetch" href="/vue-element-dict/assets/js/7.b647619a.js"><link rel="prefetch" href="/vue-element-dict/assets/js/8.4a0866ed.js"><link rel="prefetch" href="/vue-element-dict/assets/js/9.9ff5451c.js">
    <link rel="stylesheet" href="/vue-element-dict/assets/css/0.styles.2f302933.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue-element-dict/" class="home-link router-link-active"><!----> <span class="site-name">vue-element-dict</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/vue-element-dict/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/vue-element-dict/guide/" class="nav-link router-link-active">
  指南
</a></div><div class="nav-item"><a href="https://www.npmjs.com/package/vue-element-dict" target="_blank" rel="noopener noreferrer" class="nav-link external">
  npm地址
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/vue-element-dict/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/vue-element-dict/guide/" class="nav-link router-link-active">
  指南
</a></div><div class="nav-item"><a href="https://www.npmjs.com/package/vue-element-dict" target="_blank" rel="noopener noreferrer" class="nav-link external">
  npm地址
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-element-dict/guide/" aria-current="page" class="sidebar-link">介绍</a></li><li><a href="/vue-element-dict/guide/fast/" class="sidebar-link">快速开始</a></li><li><a href="/vue-element-dict/guide/directory-structure/" class="sidebar-link">目录结构</a></li><li><a href="/vue-element-dict/guide/config/" aria-current="page" class="active sidebar-link">字典包配置</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/vue-element-dict/guide/config/#配置文档说明" class="sidebar-link">配置文档说明</a></li><li class="sidebar-sub-header"><a href="/vue-element-dict/guide/config/#treesetting配置" class="sidebar-link">treesetting配置</a></li><li class="sidebar-sub-header"><a href="/vue-element-dict/guide/config/#常见问题" class="sidebar-link">常见问题</a></li></ul></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>普通字典组件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-element-dict/components/el-select-dict/" class="sidebar-link">select-dict选择器</a></li><li><a href="/vue-element-dict/components/el-radio-dict/" class="sidebar-link">radio-dict单选框</a></li><li><a href="/vue-element-dict/components/el-checkbox-dict/" class="sidebar-link">checkbox-dict多选框</a></li><li><a href="/vue-element-dict/components/el-radio-button-dict/" class="sidebar-link">radio-button-dict单选框</a></li><li><a href="/vue-element-dict/components/el-checkbox-button-dict/" class="sidebar-link">checkbox-button-dict多选框</a></li><li><a href="/vue-element-dict/components/el-tabs-dict/" class="sidebar-link">tabs-dict标签页</a></li><li><a href="/vue-element-dict/components/el-tag-dict/" class="sidebar-link">tag-dict标签</a></li><li><a href="/vue-element-dict/components/el-link-dict/" class="sidebar-link">link-dict链接</a></li><li><a href="/vue-element-dict/components/el-button-dict/" class="sidebar-link">button-dict链接</a></li><li><a href="/vue-element-dict/components/el-table-colmun-dict/" class="sidebar-link">el-table-colmun-dict表格</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>树形字典组件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-element-dict/components/el-cascader-dict/" class="sidebar-link">cascader-dict联级选项</a></li><li><a href="/vue-element-dict/components/el-tree-dict/" class="sidebar-link">tree-dict树菜单</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>其他组件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-element-dict/components/el-cascader-new/" class="sidebar-link">cascader-new联级选项</a></li><li><a href="/vue-element-dict/components/el-tree-new/" class="sidebar-link">tree-new树菜单</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>过滤器</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-element-dict/filters/dict/" class="sidebar-link">字典过滤器</a></li><li><a href="/vue-element-dict/filters/tree-dict/" class="sidebar-link">树形字典过滤器</a></li><li><a href="/vue-element-dict/filters/other/" class="sidebar-link">其他过滤器</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>方法</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-element-dict/functions/dict/" class="sidebar-link">字典方法</a></li><li><a href="/vue-element-dict/functions/tree-dict/" class="sidebar-link">树形字典方法</a></li><li><a href="/vue-element-dict/functions/other/" class="sidebar-link">其他方法</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="字典包配置"><a href="#字典包配置" class="header-anchor">#</a> 字典包配置</h1> <p><a href="/vue-element-dict/guide/directory-structure/">目录结构</a>这篇文章中字典配置文件涉及到字典配置，此篇文章详细介绍可配置项。</p> <h2 id="配置文档说明"><a href="#配置文档说明" class="header-anchor">#</a> 配置文档说明</h2> <table><thead><tr><th>字段</th> <th>类型</th> <th>说明</th> <th>默认值</th></tr></thead> <tbody><tr><td>getDictCodeApi</td> <td>promise</td> <td>必传，获取字典数据接口</td> <td>无</td></tr> <tr><td>verssion</td> <td>String</td> <td>必传 ，最新字典数据的版本号</td> <td>无</td></tr> <tr><td>elementUI</td> <td>element对象</td> <td>选传，传当前项目使用的element对象，避免element版本不一致，导致功能或样式问题</td> <td>默认element-ui@2.15.6版本</td></tr> <tr><td>query</td> <td>String</td> <td>获取字典数据接口传参的 key字段名</td> <td>type</td></tr> <tr><td>usuallyGetFileds</td> <td>String</td> <td>字符串，多个的话，英文逗号隔开，经常需要用到的字段，子项目非常适用此字段配置</td> <td>&quot;&quot;</td></tr> <tr><td>verssionKey</td> <td>String</td> <td>存入浏览器缓存的当前版本号key字段名</td> <td>currentVerssion</td></tr> <tr><td>dictDataKey</td> <td>String</td> <td>存入浏览器缓存的字典数据key字段名</td> <td>dictCodeList</td></tr> <tr><td>format</td> <td>Object</td> <td>接口返回的数据的value和label字段名，value和label的 <strong>key不能改</strong> <strong>如有配置value与label必须同时传（即使有一个与默认值一致）</strong></td> <td>{value: &quot;value&quot;, label: &quot;label&quot;}</td></tr> <tr><td>formatterRequest</td> <td>function</td> <td>对入参进行数据格式转化，将我们规定的格式，转化为后端人员接口期望传的参数 默认格式</td> <td>（query, data）=&gt; {if(!data) {return {[query]:&quot;&quot;}return [query]:&quot;&quot;}}</td></tr> <tr><td>formatterDictList</td> <td>function</td> <td>处理接口返回的数据，将返回数据处理成包期望的字典数据 data为接口返回的数据<br>V3.0.3版本开始新增可配置参数query，query为该字典类型type的值，兼容当接口仅支持单个查询且返回数据无对应字典类型时 可配置使用</td> <td>（data, query）=&gt; {return data.data.dictCodeList}</td></tr> <tr><td>formatterDictVerssion</td> <td>function</td> <td>处理接口返回的数据，返回包期望的版本号 data为接口返回的数据</td> <td>（data）=&gt; {return data.data.verssion}</td></tr> <tr><td>storage</td> <td>window的对象</td> <td>localStorage/ sessionStorage 浏览器缓存位置的配置</td> <td>localStorage</td></tr> <tr><td>isGetAll</td> <td>Boolean</td> <td>是否获取全部字典值</td> <td>false</td></tr> <tr><td>localDictCodes</td> <td>Object</td> <td>本地项目写死的字典数据</td> <td>{}</td></tr> <tr><td>getDictEveryTime</td> <td>Boolean</td> <td>是否每次进入页面都加载请求字典</td> <td>false</td></tr> <tr><td>filterDataFun</td> <td>Function</td> <td>组件过滤数据方法函数 接收该字典类型的数据 默认不变</td> <td>(list) =&gt; { return list }</td></tr> <tr><td>disabledDataFun</td> <td>Function</td> <td>组件禁用数据方法函数 接收该字典类型的数据 默认不变</td> <td>(list) =&gt; { return list }</td></tr> <tr><td>treeSetting</td> <td>Object</td> <td>数组转树形数据需要的配置</td> <td>详见<a href="/vue-element-dict/guide/config/#treesetting配置">treesetting配置</a></td></tr></tbody></table> <p>::: tips</p> <p><code>formatterRequest</code>接收两个参数，第一个是 query，默认值为type，第二个是字典类型，多个时默认英文逗号隔开。此配置的目的就是将我们默认的传参格式，转化为后端接口想要的格式。</p> <p><code>formatterDictList</code>接收一个参数data，这个的值就是请求字典接口返回的最外层的数据，将后端返回的数据转化为我们包想要的格式，然后return回来即可。</p> <p><code>V3.0.3版本开始 formatterDictList</code>接收两个参数，第一个是data，第二个是query，data就是请求字典接口返回的最外层的数据，query就是请求的字典类型，将后端返回的数据转化为我们包想要的格式，然后return回来即可。</p> <p>:::</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// V3.0.3版本开始 支持接口只能请求一个字典类型时 的配置</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> getDicts <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;@/api/system/dict/data&quot;</span>
<span class="token keyword">import</span> localDictCodes <span class="token keyword">from</span> <span class="token string">&quot;@/assets/data/dict&quot;</span>
<span class="token keyword">import</span> elementUI <span class="token keyword">from</span> <span class="token string">&quot;element-ui&quot;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">getDictCodeApi</span><span class="token operator">:</span> getDicts<span class="token punctuation">,</span> <span class="token comment">//必传 获取字典数据接口</span>
  localDictCodes<span class="token punctuation">,</span> <span class="token comment">//选填 项目写死的字典数据</span>
  <span class="token literal-property property">elementUI</span><span class="token operator">:</span> elementUI<span class="token punctuation">,</span>
  <span class="token comment">// 格式化请求参数，query为 配置项query的值， data为 请求传入的参数，也就是字典类型，多个字典时用英文逗号隔开</span>
  <span class="token function-variable function">formatterRequest</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">query<span class="token punctuation">,</span> data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> data
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token literal-property property">format</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">value</span><span class="token operator">:</span> <span class="token string">&quot;dictValue&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">label</span><span class="token operator">:</span> <span class="token string">&quot;dictLabel&quot;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function-variable function">formatterDictList</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">data<span class="token punctuation">,</span> query</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      <span class="token punctuation">[</span>query<span class="token punctuation">]</span><span class="token operator">:</span> data<span class="token punctuation">.</span>data
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token literal-property property">version</span><span class="token operator">:</span> <span class="token string">&quot;0.0.1&quot;</span><span class="token punctuation">,</span>
  <span class="token comment">// 项目无法实时返回版本时  返回和配置一样的版本号，避免版本号不一致 缓存被删除</span>
  <span class="token function-variable function">formatterDictVerssion</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token string">&quot;0.0.1&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="treesetting配置"><a href="#treesetting配置" class="header-anchor">#</a> treesetting配置</h2> <table><thead><tr><th style="text-align:center;">字段名</th> <th style="text-align:center;">说明</th> <th style="text-align:center;">默认值</th></tr></thead> <tbody><tr><td style="text-align:center;">idField</td> <td style="text-align:center;">id字段名，唯一标识</td> <td style="text-align:center;">id</td></tr> <tr><td style="text-align:center;">parentIdField</td> <td style="text-align:center;">父节点字段名，父节点字段标识</td> <td style="text-align:center;">parentId</td></tr> <tr><td style="text-align:center;">childrenField</td> <td style="text-align:center;">数组转树形数据后子节点字段名</td> <td style="text-align:center;">children</td></tr> <tr><td style="text-align:center;">firstId</td> <td style="text-align:center;">根节点数据值，默认字符串 0</td> <td style="text-align:center;">“0”</td></tr> <tr><td style="text-align:center;">labelField</td> <td style="text-align:center;">展示值字段名</td> <td style="text-align:center;">label</td></tr> <tr><td style="text-align:center;">labelArrField</td> <td style="text-align:center;">树形数据数组字段名（如[&quot;福建省&quot;,&quot;漳州市&quot;,&quot;诏安县&quot;]）</td> <td style="text-align:center;">labelArr</td></tr> <tr><td style="text-align:center;">idArrField</td> <td style="text-align:center;">树形数据数组字段名（如[&quot;350000&quot;,&quot;350600&quot;,&quot;350624&quot;]）</td> <td style="text-align:center;">idArr</td></tr> <tr><td style="text-align:center;">levelField</td> <td style="text-align:center;">层级字段名，展示层级</td> <td style="text-align:center;">level</td></tr> <tr><td style="text-align:center;">level</td> <td style="text-align:center;">配置第一级为第几级</td> <td style="text-align:center;">1</td></tr> <tr><td style="text-align:center;">leafField</td> <td style="text-align:center;">叶子节点字段名</td> <td style="text-align:center;">leaf</td></tr></tbody></table> <!----> <h2 id="常见问题"><a href="#常见问题" class="header-anchor">#</a> 常见问题</h2> <ol><li><p>后端无返回版本号时怎么办。</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">/* 
答：当后端无返回版本号时，可将版本号写死固定，如0.0.1，且使用formatterDictVerssion格式化返回版本号数据写死 0.0.1（必须和前面一致）。

具体使用方法 如下：
*/</span>

<span class="token comment">//  src/api/modules/common-api.js</span>
<span class="token comment">//获取全局配置  包含版本号</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">getGlobalConfigApi</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">verssion</span><span class="token operator">:</span> <span class="token string">&quot;0.0.1&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// src/dict-setting.js 文件</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>getDictCodeApi<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;@/api/module/common-api.js&quot;</span>
<span class="token keyword">import</span> localDictCodes <span class="token keyword">from</span> <span class="token string">&quot;@/assets/data/dict.js&quot;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    getDictCodeApi<span class="token punctuation">,</span> <span class="token comment">//必传 获取字典数据接口</span>
    localDictCodes<span class="token punctuation">,</span> <span class="token comment">//选填 项目写死的字典数据</span>
    <span class="token function-variable function">formatterDictVerssion</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token comment">//data为 经过 axios 响应处理后返回的 第一级数据</span>
        <span class="token keyword">return</span> <span class="token string">&quot;0.0.1&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">//以上操作即可解决后端接口无返回版本号问题，实现方法很多，以上方法为遵循文档推荐代码的解决方式</span>
</code></pre></div></li> <li><p>后端字典接口正常请求，但是返回数据与文档要求格式不一致怎么办？</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">/*
答：此包拥有诸多配置，面对后端人员不配合修改接口返回格式时，部门字典包无能为力。此包就针对这个问题，实现对接口返回数据进行操作。让各种各样的接口数据经过您优秀的数据操作，都能适配此字典包。

具体如下：
*/</span>

<span class="token comment">// src/dict-setting.js 文件</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>getDictCodeApi<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;@/api/module/common-api.js&quot;</span>
<span class="token keyword">import</span> localDictCodes <span class="token keyword">from</span> <span class="token string">&quot;@/assets/data/dict.js&quot;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    getDictCodeApi<span class="token punctuation">,</span> <span class="token comment">//必传 获取字典数据接口</span>
    localDictCodes<span class="token punctuation">,</span> <span class="token comment">//选填 项目写死的字典数据</span>
    <span class="token function-variable function">formatterDictList</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token comment">//data为 经过 axios 响应处理后返回的 第一级数据</span>
        <span class="token keyword">const</span> dictCodeList <span class="token operator">=</span> 一系列操作后 <span class="token operator">...</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
        <span class="token keyword">return</span> dictCodeList
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div></li> <li><p>后端请求格式与字典包要求的不一致怎么办？</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">/*
答：此包拥有诸多配置，面对后端人员不愿意修改请求参数来适配字典包，部门字典包无能为力。此包就针对这个问题，实现对请求参数数据进行操作。让请求参数能适配此字典包。

具体如下：
*/</span>

<span class="token comment">// src/dict-setting.js 文件</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>getDictCodeApi<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;@/api/module/common-api.js&quot;</span>
<span class="token keyword">import</span> localDictCodes <span class="token keyword">from</span> <span class="token string">&quot;@/assets/data/dict.js&quot;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    getDictCodeApi<span class="token punctuation">,</span> <span class="token comment">//必传 获取字典数据接口</span>
    localDictCodes<span class="token punctuation">,</span> <span class="token comment">//选填 项目写死的字典数据</span>
    <span class="token function-variable function">formatterRequest</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">query<span class="token punctuation">,</span> data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token comment">//query 为字典类型参数   如  type: &quot;AAC004&quot; 中的type</span>
        <span class="token comment">//data  为字典类型数据   如  type: &quot;AAC004&quot; 中的AAC004</span>
        <span class="token keyword">const</span> req <span class="token operator">=</span> 一系列操作后 <span class="token operator">...</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
        <span class="token keyword">return</span> req
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div></li> <li><p>此字典组件使用后会调用多次接口且每个接口只请求一个字典类型的数据，能让他们在同个接口请求？</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">/*
答：针对这个问题，此包已经有预判到了，所以有个usuallyGetFileds配置项，用来配置经常请求的字典类型，这种情况下，这些字典数据就会在同个接口请求。当然如果在整个项目上或多或少 会有部分字典数据 不在usuallyGetFileds范畴内。不过此字段已经大大的解决了您的问题。
如果是项目是供iframe作为单个功能页使用，可将页面上所有使用到的字典数据配置起来就能完全达到您的要求。
*/</span>
</code></pre></div></li> <li><p>后端接口返回数据格式一致，但是字段名不一致，我该如何处理？</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">/*
答：format配置项可以解决您的问题。
具体如下
*/</span>

<span class="token comment">// src/dict-setting.js 文件</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>getDictCodeApi<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;@/api/module/common-api.js&quot;</span>
<span class="token keyword">import</span> localDictCodes <span class="token keyword">from</span> <span class="token string">&quot;@/assets/data/dict.js&quot;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    getDictCodeApi<span class="token punctuation">,</span> <span class="token comment">//必传 获取字典数据接口</span>
    localDictCodes<span class="token punctuation">,</span> <span class="token comment">//选填 项目写死的字典数据</span>
    <span class="token literal-property property">format</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token literal-property property">value</span><span class="token operator">:</span> <span class="token string">&quot;后端返回的value&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">label</span><span class="token operator">:</span> <span class="token string">&quot;后端返回的label&quot;</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre></div></li></ol></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">1/7/2023, 11:28:07 AM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/vue-element-dict/guide/directory-structure/" class="prev">
        目录结构
      </a></span> <span class="next"><a href="/vue-element-dict/components/el-select-dict/">
        select-dict选择器
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><div id="loading-mask"><div class="loading-wrapper"><span class="loading-dot loading-dot-spin"><i></i> <i></i> <i></i> <i></i></span></div></div><!----></div></div>
    <script src="/vue-element-dict/assets/js/app.796ae7e4.js" defer></script><script src="/vue-element-dict/assets/js/4.df041e95.js" defer></script><script src="/vue-element-dict/assets/js/35.0a8dc5d9.js" defer></script>
  </body>
</html>
